import request from "../utils/request";
import type { AxiosRequestConfig } from "axios";

export const updateFile = <P = any, V = any>(
  data: P,
  config?: AxiosRequestConfig
) => {
  return request({
    url: "/updateFile",
    method: "post",
    data,
    headers: {
      "Content-Type": "multipart/form-data",
    },
    ...config,
  }) as Promise<V>;
};

export const updateFileSplit = <
  P extends {
    file: FormData;
    filename: string;
    sufixname: string;
    dirname: string;
  },
  V = any
>(
  data: P,
  config?: AxiosRequestConfig
) => {
  return request({
    url: "/updateFileSplit",
    method: "post",
    data: data.file,
    headers: {
      "Content-Type": "multipart/form-data",
      filename: data.filename,
      sufixname: data.sufixname,
      dirname: data.dirname,
    },
    ...config,
  }) as Promise<V>;
};

export const mergeFile = <P = { filename: string; sufixname: string }, V = any>(
  params: P
) => {
  return request({
    url: "/mergeFile",
    method: "get",
    params,
  }) as Promise<V>;
};

export const updateFileBase = <P = any, V = any>(
  data: P,
  config?: AxiosRequestConfig
) => {
  return request({
    url: "/updateFileBase",
    method: "post",
    data,
    ...config,
  }) as Promise<V>;
};
